package com.hh.generator.core.generator;

import com.hh.generator.core.Generator;
import com.hh.generator.core.model.ClassModel;
import com.hh.generator.core.model.Config;
import org.apache.commons.lang.StringUtils;

import java.util.ArrayList;
import java.util.List;

public class ObjectGenerator extends AbstractGenerator implements Generator {

    private String templateName = "Object.java.vm";


    public String generatorRequest(Config config, String entity, String action) {
        String packageName = config.getRequestPackage().replace("xx", config.getModule());
        String className = StringUtils.capitalize(entity) + StringUtils.capitalize(action) + "Request";
        return generator(config, packageName, className);
    }

    public String generatorResponse(Config config, String entity, String action) {
        String packageName = config.getResponsePackage().replace("xx", config.getModule());
        String className = StringUtils.capitalize(entity) + StringUtils.capitalize(action) + "Response";
        return generator(config, packageName, className);
    }

    public String generator(Config config, String packageName, String className) {
        List<String> imports = new ArrayList<>();
        ClassModel model = new ClassModel();
        model.setPackageName(packageName);
        model.setImports(imports);
        model.setComment("请求对象");
        model.setAuthor(config.getClassAuthor());
        model.setDate(config.getDate());
        model.setClassName(className);
        model.setClassFullName(model.getPackageName() + "." + model.getClassName());
        return doGenerate(model, templateName);
    }

}
